#!/usr/bin/env bash

# grugly@sdf

# Converts things to other things.

source '../say.sh'

src="$2"
usg='Usage: !convert <f2c|c2f> number'

if [ -z "$3" ]; then
    res="$usg"
else 
    con="$3"
    inp="$4"
    case "$con" in
        'f2c')
            if [[ "$inp" =~ [0-9]$ ]]; then
                res="$(echo "scale=2;(5/9)*($inp-32)"|bc)°C"
            else
                res="$usg"
            fi
            ;;
        'c2f')
            if [[ "$inp" =~ [0-9]$ ]]; then
                res="$(echo "scale=2;((9/5)*$inp)+32"|bc)°F"
            else
                res="$usg"
            fi
            ;;
        *)
            res="$usg"
            ;;
    esac
fi

say "$src" "$res"

